﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using VOL.Core.Utilities;
using VOL.Entity.AttributeManager;
using VOL.Entity.DomainModels.ProductionManagement;
using VOL.Smartmanufacturing;
using VOL.Smartmanufacturing.DTO.ProductionManagement;
using VOL.Smartmanufacturing.IServices.ProductionManagement;
using VOL.Smartmanufacturing.Services.ProductionManagement;

namespace VOL.WebApi.Controllers.Smartmanufacturing.ProductionManagement
{
    /// <summary>
    /// 工单台账控制器
    /// </summary>
    [Route("api/EquipmentLedgerController")]
    [PermissionTable(Name = "EquipmentLedgerController")]
    public class EquipmentLedgerController : ControllerBase
    {

        private readonly IAddEquipmentLedger _addEquipmentLedger;
        private readonly IEquipmentLedgerShow _equipmentLedgerShow;
        private readonly IDelEquipmentLedger _delEquipmentLedger;
        private readonly IUpdateEquipmentLedger _updateEquipmentLedger;
        private readonly IBatchDeleteEquipmentLedger _batchDeleteEquipmentLedger;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="addEquipmentLedger">添加工单台账</param>
        /// <param name="equipmentLedgerShow">显示工单台账</param>
        /// <param name="delEquipmentLedger">删除工单台账</param>
        /// <param name="updateEquipmentLedger">修改工单台账</param>
        public EquipmentLedgerController(IAddEquipmentLedger addEquipmentLedger, IEquipmentLedgerShow equipmentLedgerShow, IDelEquipmentLedger delEquipmentLedger, IUpdateEquipmentLedger updateEquipmentLedger, IBatchDeleteEquipmentLedger batchDeleteEquipmentLedger)
        {
            _addEquipmentLedger = addEquipmentLedger;
            _equipmentLedgerShow = equipmentLedgerShow;
            _delEquipmentLedger = delEquipmentLedger;
            _updateEquipmentLedger = updateEquipmentLedger;
            _batchDeleteEquipmentLedger = batchDeleteEquipmentLedger;
        }

        /// <summary>
        /// 添加设备台账
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost("AddEquipmentLedgerAsync")]
        public async Task<int> AddEquipmentLedgerAsync([FromBody] EquipmentLedgerModel model)
        {
            return await _addEquipmentLedger.AddEquipmentLedgerAsync(model);
        }

        /// <summary>
        /// 显示设备台账
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet("GetEquipmentLedger")]
        public async Task<ApiPaging<EquipmentLedgerModel>> GetEquipmentLedger(EquipmentLedgerDTO equipmentLedgerDTO)
        {
            return await _equipmentLedgerShow.GetEquipmentLedger(equipmentLedgerDTO);

        }
        /// <summary>
        /// 删除设备台账
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet("DelEquipmentLedgerAsync")]
        public async Task<int> DelEquipmentLedgerAsync([FromQuery] int id)
        {
            return await _delEquipmentLedger.DelEquipmentLedgerAsync(id);
        }
        /// <summary>
        /// 删除批量设备台账
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet("BatchDeleteEquipmentLedgerAsync")]
        public async Task<int> BatchDeleteEquipmentLedgerAsync(string ids)
        {

            return await _batchDeleteEquipmentLedger.BatchDeleteEquipmentLedgerAsync(ids);
        }
        /// <summary>
        /// 修改设备台账
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost("UpdateEquipmentLedgerAsync")]
        public async Task<int> UpdateEquipmentLedgerAsync([FromBody] EquipmentLedgerModel model)
        {
            var result = await _updateEquipmentLedger.UpdateEquipmentLedgerAsync(model);
            return result;
        }
    }
}
